package cn.org.book.shop.web.controller.article;

import cn.org.book.shop.article.domain.ApUserChannel;
import cn.org.book.shop.article.service.IApUserChannelService;
import cn.org.book.shop.common.annotation.Log;
import cn.org.book.shop.common.core.controller.BaseController;
import cn.org.book.shop.common.core.domain.AjaxResult;
import cn.org.book.shop.common.core.page.TableDataInfo;
import cn.org.book.shop.common.enums.BusinessType;
import cn.org.book.shop.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * APP用户频道信息Controller
 *
 * @author julywhj
 * @date 2020-11-17
 */
@RestController
@RequestMapping("/ap/channel")
public class ApUserChannelController extends BaseController {
    @Autowired
    private IApUserChannelService apUserChannelService;

    /**
     * 查询APP用户频道信息列表
     */
    @PreAuthorize("@ss.hasPermi('ap:channel:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApUserChannel apUserChannel) {
        startPage();
        List<ApUserChannel> list = apUserChannelService.selectApUserChannelList(apUserChannel);
        return getDataTable(list);
    }

    /**
     * 导出APP用户频道信息列表
     */
    @PreAuthorize("@ss.hasPermi('ap:channel:export')")
    @Log(title = "APP用户频道信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ApUserChannel apUserChannel) {
        List<ApUserChannel> list = apUserChannelService.selectApUserChannelList(apUserChannel);
        ExcelUtil<ApUserChannel> util = new ExcelUtil<ApUserChannel>(ApUserChannel.class);
        return util.exportExcel(list, "channel");
    }

    /**
     * 获取APP用户频道信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ap:channel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(apUserChannelService.selectApUserChannelById(id));
    }

    /**
     * 新增APP用户频道信息
     */
    @PreAuthorize("@ss.hasPermi('ap:channel:add')")
    @Log(title = "APP用户频道信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApUserChannel apUserChannel) {
        return toAjax(apUserChannelService.insertApUserChannel(apUserChannel));
    }

    /**
     * 修改APP用户频道信息
     */
    @PreAuthorize("@ss.hasPermi('ap:channel:edit')")
    @Log(title = "APP用户频道信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApUserChannel apUserChannel) {
        return toAjax(apUserChannelService.updateApUserChannel(apUserChannel));
    }

    /**
     * 删除APP用户频道信息
     */
    @PreAuthorize("@ss.hasPermi('ap:channel:remove')")
    @Log(title = "APP用户频道信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(apUserChannelService.deleteApUserChannelByIds(ids));
    }
}
